package com.changanw.jedis.redisClusster;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;

import java.util.HashSet;
import java.util.Set;

/**
 * redis 集群
 */
public class RedisCluster {
    public static void main(String[] args) {
        Set<HostAndPort> nodes = new HashSet<>();
        nodes.add(new HostAndPort("127.0.0.1",7001));
        nodes.add(new HostAndPort("127.0.0.1",7002));
        nodes.add(new HostAndPort("127.0.0.1",7003));
        nodes.add(new HostAndPort("127.0.0.1",7004));
        nodes.add(new HostAndPort("127.0.0.1",7005));
        nodes.add(new HostAndPort("127.0.0.1",7006));
        nodes.add(new HostAndPort("127.0.0.1",7007));
        JedisPoolConfig config = new JedisPoolConfig();
        //连接池最大空闲数量
        config.setMaxIdle(300);
        //最大连接数
        config.setMaxTotal(1000);
        //连接最大等待时间，如果是 -1 表示没有限制
        config.setMaxWaitMillis(30000);
        //在空闲时检查有效性
        config.setTestOnBorrow(true);
        JedisCluster jedisCluster = new JedisCluster(nodes, 15000, 15000, 5, "12345", config);
        String set = jedisCluster.set("k1", "v1");
        System.out.println(set);
        String s = jedisCluster.get("k1");
        System.out.println(s);
    }
}
